<template>
  <div class="city">
    <Header></Header>
    <search :cities="cities"></search>
    <city-list :letter="letter" :cities="cities" :hot="hotCities"></city-list>
    <alphablt :cities="cities" @change="handleLetterChange"></alphablt>
  </div>
</template>
<script>
import Header from './components/Header'
import Search from './components/Search'
import CityList from './components/CityList'
import Alphablt from './components/Alphablt'
import axios from 'axios'

export default {
  data () {
    return {
      cities: {},
      hotCities: [],
      letter: ''
    }
  },
  components: {
    Header,
    Search,
    CityList,
    Alphablt
  },
  methods: {
    getCityInfo () {
      axios.get('/api/city.json').then(this.getCityInfoSucc)
    },
    getCityInfoSucc (res) {
      res = res.data
      if(res.ret && res.data) {
        let data = res.data 
        this.cities = data.cities
        this.hotCities = data.hotCities
      }
    },
    handleLetterChange (letter) {
      this.letter = letter
    }
  },
  mounted () {
    this.getCityInfo()
  },
  destroyed () {
    console.log('离开了')
  }
}
</script>
<style lang="scss" scoped>
</style>

